//
//  QLInvitedMeetDetialVC.m
//  神约
//
//  Created by qlwl on 17/2/14.
//  Copyright © 2017年 qlwl. All rights reserved.
//

#import "QLSkillInvitedDetailVC.h"
#import "QLSkillInvitedDetailCell.h"
#import "QLInvitedMeetDetailModel.h"
#import "QLInvitedMeetGoInvitVC.h"

@interface QLSkillInvitedDetailVC ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) QLInvitedMeetDetailModel * detailModel ; //

@end

@implementation QLSkillInvitedDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self netWoring];
}

#pragma mark TabDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        QLSkillInvitedDetailCell * cell = [tableView dequeueReusableCellWithIdentifier:@"QLSkillInvitedDetailCell"];
        [cell.headIma QL_setImageWithURL:[NSString stringWithFormat:@"%@%@",HTTP_BaseURL,self.detailModel.headpicurl] placeholderImage:nil];
        cell.nameLab.text = self.detailModel.userName;
        NSString * ageStr = nil;
        if (self.detailModel.sex.length > 0) {
            ageStr = [self.detailModel.sex intValue] == 0?@"女":@"男";
        }
        if (self.detailModel.age.length > 0) {
            ageStr = [NSString stringWithFormat:@"%@%@岁",ageStr,NotNullClass(self.detailModel.age)];
        }
        cell.ageLab.text = ageStr;
        if (self.detailModel.chargeType == 2) {
            cell.priceLab.text = [NSString stringWithFormat:@"%.2f元",self.detailModel.servicePrice];
        }else{
            cell.priceLab.text = nil;
        }
        cell.distanceLab.text = [NSString stringWithFormat:@"%.2fkm",self.detailModel.distince/1000];
        cell.payTypeLab.text = self.detailModel.chargeType == 1?@"真诚约":@"珍贵约";
        [cell.serviceLab setTitle:self.detailModel.typeName forState:UIControlStateNormal];
        
        return cell;
    }else if (indexPath.section == 1){
        QLSkillInvitedDetailCell2 * cell = [tableView dequeueReusableCellWithIdentifier:@"QLSkillInvitedDetailCell2"];
        cell.meetNameLab.text = self.detailModel.typeName;
        cell.addressLab.text = self.detailModel.destination;
        cell.timeLab.text = [NSString stringWithFormat:@"%@ %@",NotNilString(self.detailModel.inviteTimeRange),NotNilString(self.detailModel.inviteTimeRangeHours)];
        cell.priceLab.text = @"AA";
        if (self.detailModel.sex.length >0) {
            cell.sexLab.text = [self.detailModel.sex intValue] == 0?@"女":@"男";
        }else{
            cell.sexLab.text = @"男女不限";
        }
        cell.invitedClick = ^{
//            [self invitedNetWorking];
            QLInvitedMeetGoInvitVC * invitVC = [NSString instantiateViewControllerWithIdentifier:@"QLInvitedMeetGoInvitVC" andSBName:@"Home"];
            [self.navigationController pushViewController:invitVC animated:YES];
        };
        return cell;
    }else if (indexPath.section == 2){
        QLSkillInvitedDetailCell3 * cell = [tableView dequeueReusableCellWithIdentifier:@"QLSkillInvitedDetailCell3"];
        return cell;
    }else if (indexPath.section == 3){
        QLSkillInvitedDetailCell4 * cell = [tableView dequeueReusableCellWithIdentifier:@"QLSkillInvitedDetailCell4"];
        cell.star.enabled = NO;
        return cell;
    }
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 70;
    }else if (indexPath.section == 1){
        return 160;
    }else if (indexPath.section == 2){
        return 52;
    }else if (indexPath.section == 3){
        return 72;
    }
    return 0;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 2 || section == 3) {
        return 26;
    }
    return 0;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section == 2 || section == 3) {
        if (section == 2) {
            return @"服务备注";
        }else{
            return @"他的评价";
        }
    }
    return nil;
}

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
    return NO;
}

#pragma mark netWorking 
- (void) netWoring
{
    QLLoginModel * loginModel = [QLLoginModel accountFromSandbox];
    NSMutableDictionary * postDict = [[NSMutableDictionary alloc] init];
    postDict[@"userid"] = loginModel.userId;
    postDict[@"id"] = @"1";//self.invitedId;
    [QLNetWorking postJSONWithUrl:QLInvitedMeetDetailURL parameters:postDict isJosnRequest:YES rogress:nil success:^(id result) {
        NSLog(@"%@",result);
        if ([QLNetWorking sucess:[result objectForKey:@"mobileHead"] and:@"code" EqualToString:@"success"]) {
            self.detailModel = [QLInvitedMeetDetailModel mj_objectWithKeyValues:[[result objectForKey:@"mobileBody"] objectForKey:@"data"]];
            [self.tableView reloadData];
        }
    } fail:^(NSError *error) {
        
    }];
}

//点击应邀
- (void) invitedNetWorking
{
    QLLoginModel * loginModel = [QLLoginModel accountFromSandbox];
    NSMutableDictionary * postDict = [[NSMutableDictionary alloc] init];
    postDict[@"createby"] = loginModel.userId;
    postDict[@"lifeskillid"] = @"1";
    [QLNetWorking postJSONWithUrl:QLCreatInvitedMeetURL parameters:postDict isJosnRequest:YES rogress:nil success:^(id result) {
        if ([QLNetWorking sucess:[result objectForKey:@"mobileHead"] and:@"code" EqualToString:@"success"]) {
            
        }
        [LPPopup showInCenterOfWindowWithText:[[result objectForKey:@"mobileHead"] objectForKey:@"message"] completion:nil];
    } fail:^(NSError *error) {
        
    }];
}


@end
